﻿@using Abc.Core;
@using Abc.Application;
@model Abc.Utils.SqlSugarDbTableConfig;
@{
    ViewData["Title"] = "RSA";
}
<div class="layui-collapse" lay-filter="test">
    <div class="layui-colla-item">
        <h2 class="layui-colla-title">代码生成说明</h2>
        <div class="layui-colla-content">
            <p>1.未同时设置数据库类型和数据库连接字符串的情况下，使用系统当前配置文件中的第一个数据库</p>
            <p>2.数据库差异对比使用的是sqlsugar</p>
        </div>
    </div>

</div>
<section class="panel panel-padding">
    <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">

        <form class="layui-form" action="">
            <table class="layui-table">
                <tbody>
                    <tr>
                        <td>数据库类型</td>
                        <td>
                            <select asp-for="DbType" asp-items="Html.GetEnumSelectList<SqlSugar.DbType>()"></select>
                        </td>

                        <td>数据库连接字符串</td>
                        <td>
                            <textarea asp-for="DbConn" class="layui-textarea"></textarea>
                        </td>
                        <td>
                        </td>
                    </tr>
                    <tr>
                        <td>数据库名称</td>
                        <td><input type="text" asp-for="DatabaseName" autocomplete="off" class="layui-input"></td>
                        <td>数据库目录</td>
                        <td><textarea asp-for="DatabaseDirectory" class="layui-textarea" ></textarea></td>
                        <td>
                            <div class="layui-btn submitbtn" lay-submit lay-filter="submitCreateDb">创建数据库</div>
                            <span style="color:red;">注意 ：Oracle和个别国产库需不支持该方法，需要手动建库 </span>
                        </td>
                    </tr>

                    <tr>
                        <td>对比结果</td>
                        <td colspan="3">
                            <textarea id="result" class="layui-textarea"></textarea>
                        </td>

                    </tr>
                    <tr>
                        <td colspan="6">
                            <span style="color:red;">如果未设置数据库连接字符串，则使用当前数据库连接字符串</span>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <div class="layui-btn submitbtn" lay-submit lay-filter="submitSaveConfig">保存配置</div>
                        </td>
                        <td>
                            <div class="layui-btn submitbtn" lay-submit lay-filter="submitDifference">保存设置并对比差异</div>
                        </td>
                        <td>
                            <div class="layui-btn submitbtn" lay-submit lay-filter="submitInitTables">更新当前数据库</div>
                        </td>
                        <td>
                            <div class="layui-btn submitbtn" lay-submit lay-filter="submitUpdateDataSeed">更新数据种子</div>
                        </td>
                    </tr>
                </tbody>
            </table>

        </form>
    </div>
</section>

@*<script src="~/lib/ckeditor4/ckeditor.js"></script>*@
@section Scripts{
    <script>
        layui.define(['element', 'jquery', 'form'], function () {
            let $ = layui.jquery;
            let form = layui.form;
            let element = layui.element;
            let dtree = layui.dtree;

            //Info 初始化
            abc.infoInit();
            //差异对比
            form.on('submit(submitDifference)', function (obj) {
                abc.post({
                    url: '@(Url.Action("DbDifferenceTables"))'
                    , data: obj.field
                    , done: function (result) {
                        if (result.Succeeded) {
                            $("#result").val(result.Data);
                        }
                    }

                });

                return false;
            });

            //更新当前数据库
            form.on('submit(submitInitTables)', function (obj) {
                abc.post({ url: '@(Url.Action("InitTables"))', data: obj.field});
                return false;
            });

            //创建数据库
            form.on('submit(submitCreateDb)', function (obj) {
                abc.post({ url: '@(Url.Action("InitTables"))', data: obj.field });
                return false;
            });

            //保存配置
            form.on('submit(submitSaveConfig)', function (obj) {
                abc.post({ url: '@(Url.Action("InitTables"))', data: obj.field });
                return false;
            });


            //保存配置
            form.on('submit(submitUpdateDataSeed)', function (obj) {
                abc.post({ url: '@(Url.Action("UpdateDataSeed"))', data: obj.field });
                return false;
            });
        });
    </script>
}
